const util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
    loading: false,
    page: 1,
    showNum: 10,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  jumpJI(e) {


    let url = `/elsePage/pages/bargainDetails/bargainDetails?bargain_people_id=${e.currentTarget.dataset.id}`;
    wx.navigateTo({
      url
    })
  },
  onLoad: function(options) {
    var that = this;
    util.API('bargain/v1.wxbargain/member_bargain', {page:1,pageshow:10}).then(({
      data,
      code
    }) => {

      if (code == 200) {
        this.data.list = this.data.list.concat(data);
        this.setData({
          list: this.data.list
        })
        this.intervalTimeList(that, 1000, data)
      } else {
        this.setData({
          loading: true
        })
      }
    })
  },

  intervalTimeList(that, time, list) {
    that.data.intervals = setInterval(function() {
      for (let i = 0; i < list.length; i++) {
        let {
          hrStr,
          minStr,
          secStr,
          deviation,
          day,
          shengSR
        } = util.getTimeminus(list[i].etime)
        deviation--;
        var goodsList = 'list[' + i + '].time';
        that.setData({
          [goodsList]: {
            hrStr,
            minStr,
            secStr
          }
        });

        if (deviation < 0) {
          that.setData({
            [goodsList]: {
              hrStr: '00',
              minStr: '00',
              secStr: '00'
            }

          });
        }
      }
    }.bind(that), time);
  },
  onReachBottom: function () {
    this.data.page++
    this.notActive()
  },
  onHide: function () {
    clearInterval(this.data.intervals)
  },
  onUnload: function () {
    clearInterval(this.data.intervals)
  },
})